export const copy = (text: string): Promise<boolean> => {
  return new Promise((resolve, reject) => {
    try {
      if (navigator.clipboard && navigator.clipboard.writeText) {
        // 使用 Clipboard API
        navigator.clipboard
          .writeText(text)
          .then(() => {
            ElMessage.success("复制成功");
            resolve(true);
          })
          .catch((error) => {
            console.error(error);
            reject(false);
          });
      } else {
        const input = document.createElement("input");
        input.value = text;
        document.body.appendChild(input);
        input.select();
        document.execCommand("copy");
        document.body.removeChild(input);
        resolve(true);
        ElMessage.success("复制成功");
      }
    } catch (err) {
      console.error(err);
      reject(false);
    }
  });
};
